package com.irdstudio.efp.esb.service.impl.dxm;



import com.irdstudio.efp.esb.common.client.resp.EsbRespServiceBean;
import com.irdstudio.efp.esb.service.client.impl.BD3022001101ESBBeanCreator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.constant.ESBConstant;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.SpringContextUtils;
import com.irdstudio.efp.esb.common.client.resp.EsbRespSysHeadBean;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.common.constant.dxm.DxmEnum;
import com.irdstudio.efp.esb.service.bo.req.dxm.ReqLoanAdjLmtNoticeBean;
import com.irdstudio.efp.esb.service.bo.resp.dxm.RespLoanAdjLmtNoticeBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.facade.dxm.LoanAdjLmtNoticeService;

/**
 * 额度调整申请结果通知接口实现（广州银行 -> 度小满）
 * @author  qiuyf
 * @since 2019年3月9日 下午6:33:00
 * @version 1.0
 */
@Service("loanAdjLmtNoticeService")
public class LoanAdjLmtNoticeServiceImpl implements LoanAdjLmtNoticeService {

	private static Logger logger = LoggerFactory.getLogger(LoanAdjLmtNoticeServiceImpl.class);

	@Override
	public RespLoanAdjLmtNoticeBean loanAdjLmtNotice(ReqLoanAdjLmtNoticeBean reqLoanAdjLmtNoticeBean){
		RespLoanAdjLmtNoticeBean respLoanAdjLmtNoticeBean = new RespLoanAdjLmtNoticeBean();
		EsbRespSysHeadBean esbRespSysHeadBean = new EsbRespSysHeadBean();
		try {
			EsbRespServiceBean bd3022001101ESBBeanCreator = ESBClientFactory.buildClient().withBody(reqLoanAdjLmtNoticeBean)
					.withTradeNo(ESBConstant.TRADE_NO_30220011)
					.withScene(ESBConstant.SCENE_NO_01)
					.withESBBeanFactory((BD3022001101ESBBeanCreator) SpringContextUtils.getBean("BD3022001101ESBBeanCreator"))
					.create().sendAndReceive();
			 respLoanAdjLmtNoticeBean = bd3022001101ESBBeanCreator.getBody(RespLoanAdjLmtNoticeBean.class);
			esbRespSysHeadBean =bd3022001101ESBBeanCreator.getSysHead();
			if (EsbBizEnums.RetCodeEnum.SUCCESS.getVALUE().equals(esbRespSysHeadBean.getRetInfArry().get(0).getRetCd()) ||
					DxmEnum.RetCd.REQ_REPEAT.getValue().equals(esbRespSysHeadBean.getRetInfArry().get(0).getRetCd())) {
				logger.info(" 额度调整申请结果通知接口调用成功返回，开始进行后处理 ，请求参数： " + reqLoanAdjLmtNoticeBean + ", 返回结果： " + respLoanAdjLmtNoticeBean);
				respLoanAdjLmtNoticeBean.setRetCd(esbRespSysHeadBean.getRetInfArry().get(0).getRetCd());
				return respLoanAdjLmtNoticeBean;
			}
			
			logger.error("额度调整申请结果通知接口回调失败！返回结果： " + respLoanAdjLmtNoticeBean);
			throw new ESBException();
		} catch (Exception e) {
			logger.error("额度调整申请结果通知接口调用失败！"+e.getMessage());
		}
		return respLoanAdjLmtNoticeBean;
	}

}
